import { SequelizeModule as _SequelizeModule } from '@nestjs/sequelize';
import dayjs from 'dayjs';

export const SequelizeModule = _SequelizeModule.forRoot({
  host: 'localhost',
  dialect: 'mysql',
  database: 'wujie',
  username: 'root',
  password: 'z13692133105',
  timezone: '+08:00',
  autoLoadModels: true,
  synchronize: true,
  models: [],
  define: {
    freezeTableName: true,
    timestamps: true,
    createdAt: 'createTime',
    updatedAt: 'updateTime',
  },
  dialectOptions: {
    dateStrings: true,
    typeCast: (field, next) => {
      if (['DATETIME', 'TIMESTAMP', 'DATE'].includes(field.type)) {
        const v = field.string();
        return v ? dayjs(v).format('YYYY-MM-DD HH:mm:ss') : null;
      }
      return next();
    },
  },
})